home *** CD-ROM | disk | FTP | other *** search
/ PC Gamer (Italian) 30 / PC Gamer IT CD 30 1-2.iso / MOTS / GAMEDATA / RESOURCE / JKMRES.GOO / cog_weap_eweb_m.cog < prev    next >
Text File  |  1998-02-25  |  13KB  |  484 lines

  1. # Jedi Knight Missions Cog Script
  2. #
  3. # WEAP_EWEB_M.COG
  4. #
  5. # WEAPON 10 script - EWEB Gun
  6. #
  7. # Player can not move when using this weapon.
  8. #
  9. # - Affected by MagSealed sectors/surfaces.
  10. #
  11. # [YB & CYW]
  12. #
  13. # (C) 1997 LucasArts Entertainment Co. All Rights Reserved
  14.  
  15.  
  16. symbols
  17.  
  18. sound       mountSound=df_rif_ready.wav         local
  19. sound       dismountSound=PutWeaponAway01.wav   local
  20. sound       fireSoundSmall=EWEBFireSm1.wav      local
  21. sound       fireSoundLarge=EWEBFireBig1.wav     local
  22. sound       outSound=trprout.wav                local
  23.  
  24. template    projectile=+EWEBRound               local
  25. template        EWEBProper=+EWEB                            local
  26. template        EWEBRider=+EWEBRider                        local
  27. template        tempGhost=ghost                            local
  28.  
  29. thing       player                              local
  30. thing       thingEWEB=-1                        local
  31. thing       thingRider                          local
  32. thing       ghostRider                          local
  33.  
  34. vector      tempvec                             local
  35. vector      tempvec2                            local
  36. flex        tempflex                            local
  37. flex        tempflex2                           local
  38. flex        tempflex3                           local
  39.  
  40. flex        distortionRange                     local
  41. flex        fireWait=0.1                        local
  42. flex        powerBoost                          local
  43. flex        autoAimFOV=1                        local
  44.  
  45. flex            fOldMaxPitch                                local
  46. flex            fOldMinPitch                                local
  47.  
  48. int         attachFlags                          local
  49.  
  50. int            iFirstCamera                                local
  51.  
  52. thing       dummy                               local
  53. thing       rummy                               local
  54.  
  55. int         fireChannel=-1                      local
  56. int         mode                                local
  57.  
  58. int            imOnIt=0                                        local
  59.  
  60. int            iLastWeapon                                    local
  61. vector        vLastPosition                                local
  62. sector        sLastSector                                    local
  63. thing            tEWEBPowerup                                local
  64.  
  65. flex            fOldMass                                        local
  66.  
  67. int            iDoItNextTime=0                            local
  68.  
  69. message        playeraction
  70. message     killed
  71. message     activated
  72. message     deactivated
  73. message     selected
  74. message     deselected
  75. message     autoselect
  76. message     fire
  77. message     damaged
  78. message        timer
  79. message     join
  80.  
  81. end
  82.  
  83. # ========================================================================================
  84.  
  85. code
  86.  
  87. fire:
  88.    player = GetSourceRef();
  89.    mode = GetSenderRef();
  90.  
  91.    // Check that the player is still alive.
  92.    if(GetThingHealth(player) <= 0)
  93.    {
  94.       Return;
  95.    }
  96.  
  97.    // Check Ammo - If we are out, autoselect best weapon.
  98.    if(GetInv(player, 92) < 1.0)
  99.    {
  100.       PlaySoundThing(outSound, player, 1.0, -1, -1, 0x80);
  101.         
  102.         DeactivateWeapon(player, mode);
  103.  
  104.       if((GetAutoSwitch() & 1))
  105.          SelectWeapon(player, GetWeaponBin(AutoSelectWeapon(player, 1)));
  106.       Return;
  107.    }
  108.  
  109.         // Calculate how much the weapon's accuracy has been affected by damage.
  110. //   distortionRange = (100.0 - GetInv(player, GetWeaponBin(10))) / 3.0;
  111.     distortionRange = 0.0;
  112.  
  113.    SetPOVShake('0.0 -.003 0.0', '1.5 0.0 0.0', .05, 80.0);
  114.     if (mode == 1)
  115.     {
  116.         // Get random aiming error
  117.         randVec = VectorSet((Rand()-0.5)*distortionRange, (Rand()-0.5)*distortionRange, 0.0);
  118.         SetCollideType(player, 0);
  119.         dummy = FireProjectile(ghostRider, projectile, -1, 8, '0.0 0.15 0.0', randVec, 1.0, 0x31, autoAimFOV, 0.01);
  120.       PlaySoundThing(fireSoundSmall, player, 1.0, -1, -1, 0x80);
  121.         SetCollideType(player, 1);
  122.  
  123.         ChangeInv( player, 92, -1.0 );
  124.     }
  125.     else
  126.     {
  127.         SetCollideType(player, 0);
  128.         randVec = VectorSet(((Rand()-0.5)*distortionRange)-1.0, ((Rand()-0.5)*distortionRange)-1.0, 0.0);
  129.         dummy = FireProjectile(ghostRider, projectile, -1, 8, '0.0 0.15 0.0', randVec, 1.0, 0x31, autoAimFOV, 0.01);
  130.       PlaySoundThing(fireSoundLarge, player, 1.0, -1, -1, 0x80);
  131.  
  132.             // Fire as many projectiles as we have ammo for.
  133.       if (GetInv(player, 92) >= 2.0)
  134.         {
  135.             randVec = VectorSet(((Rand()-0.5)*distortionRange)-1.0, ((Rand()-0.5)*distortionRange)+1.0, 0.0);
  136.             rummy = FireProjectile(ghostRider, projectile, 0, 8, '0.0 0.15 0.0', randVec, 1.0, 0x31, autoAimFOV, 0.01);
  137.  
  138.             if (GetInv(player, 92) >= 3.0)
  139.             {
  140.                 randVec = VectorSet(((Rand()-0.5)*distortionRange)+1.0, ((Rand()-0.5)*distortionRange)-1.0, 0.0);
  141.                 rummy = FireProjectile(ghostRider, projectile, 0, 8, '0.0 0.15 0.0', randVec, 1.0, 0x31, autoAimFOV, 0.01);
  142.  
  143.                 if (GetInv(player, 92) >= 4.0)
  144.                 {
  145.                     randVec = VectorSet(((Rand()-0.5)*distortionRange)+1.0, ((Rand()-0.5)*distortionRange)+1.0, 0.0);
  146.                     rummy = FireProjectile(ghostRider, projectile, 0, 8, '0.0 0.15 0.0', randVec, 1.0, 0x31, autoAimFOV, 0.01);
  147.                 }
  148.             }
  149.         }
  150.  
  151.         SetCollideType(player, 1);
  152.  
  153.         ChangeInv( player, 92, -4.0 );
  154.     }
  155.  
  156.    powerBoost = GetInv(player, 63);
  157.    ChangeFireRate(player, fireWait/powerBoost);
  158.  
  159.    Return;
  160.  
  161. # ........................................................................................
  162.  
  163. activated:
  164.    player = GetSourceRef();
  165.    mode = GetSenderRef();
  166.  
  167.    if (mode == 0)
  168.       fireWait = 0.4;
  169.     else
  170.    if (mode == 1)
  171.       fireWait = 0.1;
  172.  
  173.    powerBoost = GetInv(player, 63);
  174.    ActivateWeapon(player, fireWait/powerBoost, mode);
  175.    Return;
  176.  
  177. # ........................................................................................
  178.  
  179. deactivated:
  180.    player = GetSourceRef();
  181.    DeactivateWeapon(player, mode);
  182.    Return;
  183.  
  184. # ........................................................................................
  185.  
  186. selected:
  187.     if (!imOnIt)
  188.     {
  189.       imOnIt = 1;
  190.  
  191.         player = GetSourceRef();
  192.  
  193.         sLastSector = GetThingSector(player);
  194.         vLastPosition = GetThingPos(player);
  195.         iLastWeapon = GetCurWeapon(player);
  196.         tEWEBPowerup = GetInv(player, GetWeaponBin(10));
  197.     
  198.         iFirstCamera = GetCurrentCamera();
  199.         SetCurrentCamera(0);
  200.  
  201.         StopThing(player);
  202.         SetThingPosEx(player, GetThingPos(tEWEBPowerup), GetThingSector(tEWEBPowerup));
  203.         SetActorFlags(player, 0x8000000);    // Freeze the player
  204.     
  205.             // Make the powerup non-collide and invisible.
  206.         SetThingCollide(tEWEBPowerup, 0);
  207.         SetThingFlags(tEWEBPowerup, 0x10);
  208.     
  209.             // Don't arm instantly...
  210.         SetTimerEx(0.2, 0, 0, 0);
  211.     }
  212.  
  213.     return;
  214.  
  215. # ........................................................................................
  216.  
  217. timer:
  218.     if (GetSenderID() == 0)
  219.     {
  220.         PlayMode(player, 41);
  221.         PlaySoundThing(mountSound, player, 1.0, -1, -1, 0x80);
  222.         SetArmedMode(player, 1);
  223.         jkSetWeaponMesh(player, -1);
  224.         jkClearFlags(player, 0x5);
  225.         SetCurWeapon(player, GetWeaponBin(10));
  226.  
  227.         StopThing(player);
  228. //        SetThingPosEx(player, GetThingPos(tEWEBPowerup), GetThingSector(tEWEBPowerup));
  229.         SetActorFlags(player, 0x8000000);    // Freeze the player
  230.  
  231.             // Make the main player thing invisible.
  232.         SetThingFlags(player, 0x10);
  233.  
  234.         thingEWEB = CreateThing(EWEBProper, player);
  235.         thingRider = CreateThing(EWEBRider, player);
  236.         ghostRider = CreateThing(tempGhost, player);
  237.  
  238.             // Make the rider look like the player
  239.         SetThingModel(thingRider, GetThingModel(player));
  240.  
  241.         fOldMaxPitch = SetThingMaxHeadPitch(player, 30.0);
  242.         fOldMinPitch = SetThingMinHeadPitch(player, -30.0);
  243.  
  244.         AttachThingToThing(thingEWEB, player);
  245.         AttachThingToThing(thingRider, player);
  246.         AttachThingToThing(ghostRider, player);
  247.  
  248.         fOldMass = GetThingMass(player);
  249.         SetThingMass(player, 0.0);
  250.  
  251.             // Move the rider up a bit.
  252.         tempvec = GetThingPos(ghostRider);
  253.         tempvec = VectorAdd(tempvec, vectorset(0, 0, 0.25));
  254.         SetThingPos(ghostRider, tempvec);
  255.  
  256.         iDoItNextTime = 1;
  257.         SetActionCog(GetSelfCog(),    0x80004120);
  258.  
  259.         SetCameraFocus(0, ghostRider);
  260.     }
  261.     else
  262.     if (GetSenderID() == 1)
  263.     {
  264.         if (thingEWEB != -1)
  265.         {
  266. //            SendTrigger(-1, 99002, thingEWEB, GetLocalPlayerThing(), 0, 0);
  267.             SyncThingAttachment(thingEWEB);
  268.         }
  269.     }
  270.  
  271.    Return;
  272.  
  273. # ........................................................................................
  274.  
  275. deselected:
  276.     if (imOnIt)
  277.     {
  278.       imOnIt = 0;
  279.  
  280.         player = GetSourceRef();
  281.  
  282.         DeactivateWeapon(player, mode);
  283.  
  284.         SetCurrentCamera(iFirstCamera);
  285.  
  286.         SetInvActivated(player, GetWeaponBin(10), 0);
  287.         SetThingPosEx(player, vLastPosition, sLastSector);
  288.     
  289.         SetThingCollide(tEWEBPowerup, 1);
  290.         ClearThingFlags(tEWEBPowerup, 0x10);
  291.     
  292.         ClearActorFlags(player, 0x8000000);    // Unfreeze the player
  293.     
  294.         ClearThingFlags(player, 0x10);
  295.  
  296.         SetThingMass(player, fOldMass);
  297.     
  298.         SetThingMaxHeadPitch(player, fOldMaxPitch);
  299.         SetThingMinHeadPitch(player, fOldMinPitch);
  300.     
  301.         DestroyThing(thingEWEB);
  302.         DestroyThing(thingRider);
  303.         DestroyThing(ghostRider);
  304.  
  305.         thingEWEB = -1;
  306.     
  307.         PlaySoundThing(dismountSound, player, 1.0, -1, -1, 0x80);
  308.  
  309.         SetCameraFocus(0, jkGetLocalPlayer());
  310.     
  311.         SetActionCog(-1, 0);
  312.     }
  313.  
  314.    Return;
  315.  
  316. # ........................................................................................
  317.  
  318. autoselect:
  319.    player = GetSourceRef();
  320.  
  321.         // Default to returning -1.
  322.     ReturnEx(-1);
  323.  
  324.     if (IsInvActivated(player, GetWeaponBin(10)))
  325.    {
  326.             // If the player has ammo
  327.       if(GetInv(player, 92) != 0.0)
  328.         {
  329.             attachFlags = GetAttachFlags(player);
  330.  
  331.                 // Don't arm if we're not on the ground or
  332.                 // if we're in the process of Force jumping.
  333.             if ((attachFlags & 3) && (!IsInvActivated(player, 21)))
  334.                 ReturnEx(999.0);
  335.         }
  336.    }
  337.  
  338.    Return;
  339.  
  340. # ........................................................................................
  341.  
  342. damaged:
  343.     if (GetCurWeapon(player) == 10)    // Only take damage if the EWEB is selected,
  344.     {
  345.             // Knock the player off if we feel like it.
  346.         if (GetParam(0) > (rand() * 100 + 50))
  347.             SelectWeapon(player, GetWeaponBin(AutoSelectWeapon(player, 1)));
  348.  
  349.         if (GetSourceRef())                // if there is a source thing,
  350.         {
  351.             if (GetParam(1) & 6)            // this is energy or fire damage,
  352.             {
  353.                                                 // And the shot struck the EWEB.
  354.                 tempflex = ThingViewDot(player, GetSourceRef());
  355.                 if ((tempflex > 0.70) || (tempflex < -0.70))
  356.                 {
  357.                     ReturnEx(GetParam(0) / 2);
  358.                     Return;
  359.                 }
  360.             }
  361.         }
  362.     }
  363.  
  364.         // Shot did not strike the EWEB.  Forward all damage.
  365.    ReturnEx(GetParam(0));
  366.  
  367.     Return;
  368.  
  369. # ........................................................................................
  370.  
  371. killed:
  372.    if (player == GetSenderRef())
  373.    {
  374.             // If the actor is killed while armed with the
  375.             // EWEB, release the movement inhibitions.
  376.         ClearActorFlags(player, 0x8000000);
  377.  
  378.         SetActionCog(-1, 0);
  379.    }
  380.    Return;
  381.  
  382. # ........................................................................................
  383.  
  384. playeraction:
  385.     if (GetParam(0) == 8.0 || GetParam(0) == 5.0)        // Pitch or yaw
  386.       iDoItNextTime = 1;
  387.  
  388.     if (GetParam(0) == 31.0)        // Frame update
  389.     {
  390.         if (GetThingMass(player) > 0.0)    // Detect if a load game has occurred (object mass is not saved)
  391.         {
  392.                 // Make some corrections.
  393.             SetThingMass(player, 0.0);
  394.             SetThingMaxHeadPitch(player, 30.0);
  395.             SetThingMinHeadPitch(player, -30.0);
  396.  
  397.             SetThingPosEx(thingEWEB, GetThingPos(tEWEBPowerup), GetThingSector(tEWEBPowerup));
  398.             SetThingLook(thingEWEB, GetThingLVEC(player));
  399.  
  400.             AttachThingToThing(thingEWEB, player);
  401.  
  402.             iDoItNextTime = 1;
  403.         }
  404.  
  405.         if (iDoItNextTime == 1)
  406.         {
  407.             iDoItNextTime = 0;
  408.     
  409.                 // Spin the rider around
  410.             tempflex = GetThingJointAngle(thingEWEB, 7);
  411.     
  412.                 // Correct some stuff.
  413.             tempvec = GetThingLVecPYR(player);
  414.             tempvec = VectorSet(tempflex, VectorY(tempvec), 0.0);
  415.             SetThingLookPYR(thingRider, tempvec);
  416.             SetThingLookPYR(ghostRider, tempvec);
  417.     
  418.             tempflex3 = tempflex-8.0;
  419.             tempflex2 = (-0.06) * cos(tempflex3);
  420.             tempflex3 = (sin(tempflex) * (-0.060)) + 0.047;
  421.     
  422.             tempflex2 = tempflex2 - (0.12 * sin(tempflex));
  423.     
  424.             tempvec = GetThingPos(player);
  425.             tempvec2 = GetThingLVec(player);
  426.             tempvec2 = VectorScale(tempvec2, tempflex2);
  427.             tempvec = VectorAdd(tempvec, tempvec2);
  428.             tempvec = VectorAdd(tempvec, vectorset(0, 0, tempflex3));
  429.     
  430.             tempvec2 = VectorAdd(tempvec, vectorset(0, 0, ((-0.12) * (1-cos(tempflex)))));
  431.             SetThingPos(thingRider, tempvec2);
  432.     
  433.             tempvec = GetThingPos(player);
  434.             tempvec = VectorAdd(tempvec, '0 0 -0.065');
  435.             tempvec = VectorAdd(tempvec, VectorSet(0, 0, 0.13 * cos(tempflex)));
  436.             tempvec2 = GetThingLVec(player);
  437.             tempvec2 = VectorScale(tempvec2, -0.13 * sin(tempflex));
  438.             tempvec = VectorAdd(tempvec, tempvec2);
  439.             SetThingPos(ghostRider, tempvec);
  440.  
  441.             if (IsMulti())
  442.                 SyncThingPos(thingEWEB);
  443.  
  444. //            SetThingPos(thingRider, tempvec);
  445.         }
  446.     }
  447.  
  448.  
  449.     if (GetParam(0) == 14.0)            // Other action
  450.     {
  451.         if (GetParam(2) == 0.0)            // Everything is OK except cycle camera.
  452.         {
  453.             ReturnEx(0.0);
  454.             return;
  455.         }
  456.     }
  457.  
  458.     if (GetParam(0) == 8.0)        // Pitch
  459.     {
  460.             // Pitch the rider
  461.         tempvec = GetThingLVecPYR(player);
  462.         tempvec = VectorSet(GetParam(2), VectorY(tempvec), 0.0);
  463.         SetThingLookPYR(thingRider, tempvec);
  464.         SetThingLookPYR(ghostRider, tempvec);
  465.  
  466.             //    Pitch the EWEB
  467.       SetThingJointAngle(thingEWEB, 7,    GetParam(2));
  468.  
  469.             // Tell everyone else to pitch their EWEB.
  470.         if (IsMulti())
  471.             SendTrigger(-1, 99003, thingEWEB, 7, GetParam(2), 0);
  472.     }
  473.  
  474.     ReturnEx(1.0);
  475.    Return;
  476.  
  477. join:
  478.     SetTimerEx(1.0, 1, 0, 0);
  479.     SetTimerEx(2.0, 1, 0, 0);
  480.     SetTimerEx(5.0, 1, 0, 0);
  481.     return;
  482.  
  483. end
  484.